//
//  GWMenuViewController.m
//  GiftWanted
//
//  Created by lanou on 15/11/5.
//  Copyright © 2015年 陈文杰. All rights reserved.
//

#import "GWMenuViewController.h"
#import "GWNavigationController.h"
#import "GWHomeViewController.h"
#import "GWCategoryViewController.h"
#import "GWHotViewController.h"
#import "UIViewController+REFrostedViewController.h"
#import "GWMenuCell.h"
#import "GWRaidersDetailViewController.h"
#import "GWShopViewController.h"

@interface GWMenuViewController ()

@property (nonatomic, strong) NSMutableArray *imgArr;

@end

@implementation GWMenuViewController
- (NSMutableArray *)imgArr {
    
    if (!_imgArr) {
        _imgArr = [NSMutableArray arrayWithCapacity:0];
        UIImage *img1 = [UIImage imageNamed:@"主页"];
        UIImage *img2 = [UIImage imageNamed:@"热门"];
        UIImage *img3 = [UIImage imageNamed:@"分类"];
        UIImage *img4 = [UIImage imageNamed:@"美好小物"];
        UIImage *img5 = [UIImage imageNamed:@"好店推荐"];
        [_imgArr addObject:img1];
        [_imgArr addObject:img2];
        [_imgArr addObject:img3];
        [_imgArr addObject:img4];
        [_imgArr addObject:img5];
    }
    return _imgArr;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tableView.separatorColor = [UIColor colorWithRed:150/255.0f green:161/255.0f blue:177/255.0f alpha:1.0f];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.opaque = NO;  //opaque 不透明的
    self.tableView.backgroundColor = [UIColor clearColor];
    self.tableView.separatorStyle = UITableViewCellEditingStyleNone;
    self.tableView.tableHeaderView = ({
        
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 184.0f)];
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 40, 100, 100)];
        imageView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
        imageView.image = [UIImage imageNamed:@"礼物"];
        imageView.layer.masksToBounds = YES;
        imageView.layer.cornerRadius = 50.0;
        imageView.layer.borderColor = [UIColor whiteColor].CGColor;
        imageView.layer.borderWidth = 3.0f;
        imageView.layer.rasterizationScale = [UIScreen mainScreen].scale;
        imageView.layer.shouldRasterize = YES;
        imageView.clipsToBounds = YES;
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 150, 0, 24)];
        label.text = @"";
        label.font = [UIFont fontWithName:@"HelveticaNeue" size:21];
        label.backgroundColor = [UIColor clearColor];
        label.textColor = [UIColor colorWithRed:62/255.0f green:68/255.0f blue:75/255.0f alpha:1.0f];
        [label sizeToFit];
        label.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
        
        [view addSubview:imageView];
        [view addSubview:label];
        view;
    });
}

#pragma mark - UITableView Delegate
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    
    cell.backgroundColor = [UIColor clearColor];
    cell.textLabel.textColor = [UIColor colorWithRed:62/255.0f green:68/255.0f blue:75/255.0f alpha:1.0f];
    cell.textLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:17];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row == 0) {
        GWHomeViewController *homeViewController = [[GWHomeViewController alloc] init];
        GWNavigationController *navigationController = [[GWNavigationController alloc] initWithRootViewController:homeViewController];
        self.frostedViewController.contentViewController = navigationController;
    } else if (indexPath.row == 1) {
        GWHotViewController *hotViewController = [[GWHotViewController alloc] init];
        GWNavigationController *navigationController = [[GWNavigationController alloc] initWithRootViewController:hotViewController];
        self.frostedViewController.contentViewController = navigationController;
    } else if (indexPath.row == 2){
        GWCategoryViewController *categoryViewController = [[GWCategoryViewController alloc] init];
        GWNavigationController *navigationController = [[GWNavigationController alloc] initWithRootViewController:categoryViewController];
        self.frostedViewController.contentViewController = navigationController;
    } else if (indexPath.row == 3) {
//        NSLog(@"美好小物");
        GWRaidersDetailViewController *raidersDetailVC = [[GWRaidersDetailViewController alloc] init];
        raidersDetailVC.name = @"每日十件美好小物";
        raidersDetailVC.id_s = [NSNumber numberWithInteger:22];
        GWNavigationController *navigationController = [[GWNavigationController alloc] initWithRootViewController:raidersDetailVC];
        self.frostedViewController.contentViewController = navigationController;
        
    } else if (indexPath.row == 4) {
        NSLog(@"好店推荐");
        GWShopViewController *shopVC = [[GWShopViewController alloc] init];
        GWNavigationController *navigationController = [[GWNavigationController alloc] initWithRootViewController:shopVC];
        self.frostedViewController.contentViewController = navigationController;
    }
    
    [self.frostedViewController hideMenuViewController];
}

#pragma mark - UITableView DataSource
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return 50;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 5;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *cellIdentifier = @"Cell";
    
    GWMenuCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    
    if (cell == nil) {
        cell = [[GWMenuCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    
    
    NSArray *titles = @[@"首页", @"热门", @"分类", @"美好小物", @"好店推荐"];
    cell.menuLabel.text = titles[indexPath.row];
    cell.menuImg.image = self.imgArr[indexPath.row];
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
